package com.ruoyi.common.enums;

import io.swagger.annotations.ApiModel;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

@Getter
@ApiModel(value = "HTTP方法枚举类", description = "HTTP请求方法枚举")
public enum HttpMethodEnum{
    GET(1, "get"),
    POST(2, "post"),
    PUT(3, "put"),
    DELETE(4, "delete"),
    PATCH(5, "patch");

    private final int code;
    private final String method;

    HttpMethodEnum(int code, String method) {
        this.code = code;
        this.method = method;
    }

    private static final Map<Integer, HttpMethodEnum> codeMap = new HashMap<>();

    static {
        for (HttpMethodEnum httpMethodEnum : HttpMethodEnum.values()) {
            codeMap.put(httpMethodEnum.getCode(), httpMethodEnum);
        }
    }

    public static HttpMethodEnum fromCode(Integer code) {
        return codeMap.get(code);
    }

    public static boolean containsKey(int code) {
        return codeMap.containsKey(code);
    }
}